package pushtest.mobike.com.mtpush.ui.adapter

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.graphics.Color
import android.os.Build
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.entity.MultiItemEntity
import pushtest.mobike.com.mtpush.R

/**
 * @author  wangxiaolong
 * @time    2018/11/29
 * @desc
 */
class ScrollingViewAdapter(id: Int, values: List<String>) :
  BaseQuickAdapter<String, BaseViewHolder>(id, values) {

  override fun convert(helper: BaseViewHolder, item: String) {
    helper.setText(android.R.id.text1, item)
    helper.setBackgroundColor(android.R.id.text1, Color.WHITE)

  }


}


class MyMultiItem(val type: Int, val value: String) : MultiItemEntity {
  override fun getItemType(): Int {
    return type
  }


  companion object {
    const val tip = 0
    const val unlock = 1
    const val ad = 2
  }

}

class ScrollingSectionAdapter(data: List<MyMultiItem>, val lisenter: Animator.AnimatorListener) :
  BaseMultiItemQuickAdapter<MyMultiItem, BaseViewHolder>(data) {

  init {

    addItemType(MyMultiItem.tip, R.layout.layout_top_tip)
    addItemType(MyMultiItem.unlock, R.layout.layout_unlock)
    addItemType(MyMultiItem.ad, R.layout.layout_ad)
  }


  override fun convert(helper: BaseViewHolder, item: MyMultiItem) {

    when (item.type) {
      MyMultiItem.tip -> {
        if (getItem(0) == item) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            helper.getView<TextView>(R.id.tip).animate().translationY(0F)
              .setListener(lisenter).start()
          }
        }
        helper.setText(R.id.tip, item.value)

      }
      MyMultiItem.unlock -> {
        helper.addOnClickListener(R.id.service)
          .addOnClickListener(R.id.unlcok)
          .addOnClickListener(R.id.report)

      }
      MyMultiItem.ad -> {
        Glide.with(helper.getView(R.id.ad) as View).load(item.value)
          .into(helper.getView(R.id.ad) as ImageView)

      }

    }

  }

}